package com.fengwk.cv4j.ind;

import org.junit.Test;
import org.nd4j.linalg.factory.Nd4j;

import com.fengwk.cv4j.factory.ind.INDViewFactory;
import com.fengwk.cv4j.view.View;
import com.fengwk.cv4j.view.ind.INDArrayWrap;

public class Mmul {

    @Test
    public void test() {
        INDViewFactory f = new INDViewFactory();
        View<INDArrayWrap> W = f.of(Nd4j.create(new float[][] {
            {1, 2, 3},
            {4, 5, 6}
        }));
        View<INDArrayWrap> X = f.of(Nd4j.create(new float[][] {
            {7, 8},
            {9, 10},
            {11, 12},
        }));
        View<INDArrayWrap> Z = f.of(Nd4j.create(new float[][] {
        	{7, 8},
            {9, 10}
        }));
        
        View<INDArrayWrap> mmul = f.mmul(W, X);
        
        View<INDArrayWrap> d_mmul_W = mmul.gradient(W);
        View<INDArrayWrap> d_mmul_X = mmul.gradient(X);
        
        View<INDArrayWrap> mmul_Z = f.mmul(Z, Z);
        
        View<INDArrayWrap> d_mmul_Z = mmul_Z.gradient(Z);
        
        View<INDArrayWrap> d2_mmul_Z = d_mmul_Z.gradient(Z);
        
        System.out.println("------mmul------");
        System.out.println(mmul.compute());
        System.out.println("------d_mmul_W------");
        System.out.println(d_mmul_W.compute());
        System.out.println("------d_mmul_X------");
        System.out.println(d_mmul_X.compute());
        
       
        System.out.println("------mmul_Z------");
        System.out.println(mmul_Z.compute());
        System.out.println("------d_mmul_Z------");
        System.out.println(d_mmul_Z.compute());
        
        System.out.println("------d2_mmul_Z------");
        System.out.println(d2_mmul_Z.compute());
    }
    
}
